<?php
// Init owncloud
require_once(OC_App::getAppPath('resumes') . "/lib/resume.php");
$lang = PFactory::getLanguage();
$lang->load("com_jobs", JPATH_SITE, "zh-CN");

OCP\JSON::callCheck();
$companyid = 0;
if(!OC_User::isLoggedIn()) {
   $app = PFactory::getApplication();
   $companyid = $app->getUserState('resumeshare_companyid', 0);
   if(!$companyid) {
      echo '<div class="hr_resumes_match" id="hr_resumes_match">
            <div class="hr_resumes_matchinner">
            <div class="hr_top5match" style="text-align:center;">
            <div class="hr_top5uppoint"></div>
            <div class="closediv"></div>';
      echo '您需要先登录';
      echo '</div></div></div>';
      exit;
   }
} else {
   if (PFactory::isJobseekerUser()) {
      echo '<div class="hr_resumes_match" id="hr_resumes_match">
            <div class="hr_resumes_matchinner">
            <div class="hr_top5match" style="text-align:center;">
            <div class="hr_top5uppoint"></div>
            <div class="closediv"></div>';
      echo '您不是企业用户';
      echo '</div></div></div>';
      exit;
   }
}

$resumeid = JRequest::getInt('resumeid', 0);

$model = new PResumesModelResume();
$matchDetail = $model->getMatchDetail($resumeid, $companyid);

$marriagearr = $moreskillarr = $skillarr = array();

if(empty($matchDetail) || count($matchDetail) <= 0) {
   echo '<div class="hr_resumes_match" id="hr_resumes_match">
         <div class="hr_resumes_matchinner">
         <div class="hr_top5match" style="text-align:center;">
         <div class="hr_top5uppoint"></div>
         <div class="closediv"></div>';
   echo '没有详细信息';
   echo '</div></div></div>';
   exit;
}
?>

<div class="hr_resumes_match" id="hr_resumes_match">
   <div class="hr_resumes_matchinner">
      <div class="hr_top5match">
         <div class="hr_top5uppoint"></div>
         <div class="closediv"></div>
         <div class="hr_top5img"></div>
         <div class="hr_resumes_matchinner_table">
            <table class="medium" width="100%" border="0" cellpadding="0" cellspacing="0" style="top:0px;">
               <tr>
                  <th width="20%" align="left">匹配项</th>
                  <th width="28%" align="left">匹配要求</th>
                  <th width="20%" align="left">匹配度</th>
                  <th width="32%" align="left">简历情况</th>
               </tr>
               <?php foreach ($matchDetail as $k => $q) :?>
               <?php
               if (!empty($q->answer)){
                  if ($q->alias == 'MARRIAGE') {
                     $marriagearr[] = $q;
                  }elseif($q->alias == 'MORESKILL'){
                     $moreskillarr[] = $q;
                  }elseif($q->alias == 'SKILL'){
                     $skillarr[] = $q;
                  }
               }
               ?>
               <?php if ($q->alias != 'MARRIAGE' && $q->alias != 'MORESKILL'): ?>
               <?php
               $match_color = $q->match_degree > 79 ? 'green' :
                                    ($q->match_degree > 49 ? 'blue' :
                                     ($q->match_degree > 0 ? 'orange' : 'gray')
                                    );
               ?>
               <tr>
                  <td><b><?=$q->text_hr?></b></td>
                  <td><?=$q->expected_answer?></td>
                  <td>
                     <div class="match_degree"><div class="<?=$match_color?>" style="width:<?=$q->match_degree?>%;"></div></div><span class="match_degree_num <?=$match_color?>"><?=$q->match_degree?>%</span>
                  </td>
                  <td><?=$q->answer == '无 个月' ? '无' : $q->answer ?></td>
               </tr>
               <?php endif; ?>
               <?php endforeach; ?>
            </table>
         </div>
      </div>

      <?php if(!empty($marriagearr) || !empty($moreskillarr)): ?>
      <div class="matchmoreinfo_detail">
         <?php if(!empty($marriagearr)): ?>
            <table class="medium" width="100%" border="0" cellpadding="0" cellspacing="0" style="top:0px;">
            <?php foreach ($marriagearr as $k => $a):  ?>
               <?php if(!empty($a->answer)): ?>
               <tr>
                  <td width="55"><b><?=$a->text_hr ?></b></td>
                  <td><?=$a->answer ?></td>
               </tr>
               <?php endif; ?>
            <?php endforeach; ?>
            </table>
         <?php endif; ?>
         <?php if(!empty($moreskillarr)): ?>
            <table class="medium" width="100%" border="0" cellpadding="0" cellspacing="0" style="top:0px;">
               <tr>
                  <td width="55"><b><?php echo (count($skillarr)>=1)? '更多':'' ; ?>技能</b></td>
                  <td style="padding:0px;">
                     <table width="100%" border="0" cellpadding="0" cellspacing="0" style="top:0px;">
                        <?php foreach ($moreskillarr as $k => $b):
                        ?>
                        <tr>
                           <td width="30%"><?=$b->skill ?></td>
                           <td width="18%"><?=$b->level ?></td>
                           <td width="52%"><?=$b->exp ?>个月</td>
                        </tr>
                        <?php endforeach; ?>
                     </table>
                  </td>
               </tr>
            </table>
        <?php endif; ?>
      </div>
      <?php endif; ?>
   </div>
</div>
